And this in the next video we will create forward looking portfolios with many constituents.
So our six stocks and you will see in this and the next video that this is not that easy.
So we are still important.
The returns data frame with the daily returns of our six stocks and also the market the portfolio.
And still we have imported the covariance matrix and uh here we are only interested in the covariance
us of the six stocks.
So we exclude here the market portfolio and we only select the covariance as of our six constituents.
And also we have still imported the summary data frame with uh the annualized risk return systematic
risk and better effect of our six constituents and the market portfolio.
And also here we drop the market portfolio and the safe.
The summary data frame with the constituents and the Arab summary constituents
and also the many assets of many constituents.
First of all we have to make predictions for the returns of the single assets and then calculate the
expected return of the random portfolios and we create another column for our summary constituents data
frame expected return 1 and the reset.
The expected return of the Amazon stock to 25 percent then for Boeing 15 percent.
Disney 8 percent.
IBM 8 percent.
Coca-Cola 10 and Microsoft 15 percent.
So that's our expected return here and again we have uh six assets.
So our six constituents.
And in this video we want to create 1 million random portfolios
and therefore first of all we said that the random C to a 1 2 3.
And we create a matrix uh with 1 million times 6 random numbers between 0 and 1 and we reshape them
into 1 million rows and 6 columns.
So that's the matrix here.
And then we normalize the elements in the matrix and create the weights.
So this is actually nothing new so that's uh the weights of one million random portfolios.
And then we can calculate the expected return of these 1 million random portfolios by having here our
expected return 1 column and we apply the top method and pass the transpose the weights matrix here
and here we get an umpire rate with 1 million elements and each element is actually a expected return
of one random portfolio and the the same we can do for the risk so we can calculate the expected risk
of our 1 million random portfolios.
So we take the square root to calculate the standard deviation and then we use the dot method on the
covariance matrix and pass the transpose the weights matrix then we transpose the result and multiply
it again with the weights matrix and then we take the sum over all rows so let's have a look here.
And we should actually get for one million random portfolios of 1000000 times the expected risk in terms
of standard deviations.
So here we have a number higher array also with the 1000000 elements.
So we have in the risk an umpire race 1 million elements and in the returns an umpire Ray 1 million
elements and now the next step.
We also want to calculate the expected chop ratio of our 1 million portfolios.
And therefore we need an approximation for the risk free return.
And let's simply use here 2 percent.
And then we can also calculate the SAP ratio.
So we have the returns of our portfolios minus the risk free rate divided by the risk and finally we
can create a summary data frame with the three columns so we have the returns of our 1 million portfolios.
Then the expected risk and the expected chop ratio so that's the summary data frame with the one million
portfolios and then we can also visualize our 1 million portfolios with the risk on the x axis and the
return on the y axis
so that's our cloud of portfolios.
And this looks pretty amazing.
So here we have the efficient frontier and now we can also search for the maximum Sharpe Ratio portfolio.
So first before we use the described method on our summary data frame and we can see here that uh the
max Sharpe Ratio portfolio has a sharp ratio of 0 point 8 8 3 4 and then with the idea smacks method
we can also get uh the index label of the max operator or portfolio and this is the portfolio with the
index label eight hundred seventy three thousand nine hundred fifteen and we can also filter for that
portfolio.
So let's have a look here and we have a return of sixteen point one three percent and a risk of 16 percent.
And then finally we can also get to the rates of the max sharp racial portfolio bypassing the index
label to the weights matrix and to have it more explicit we can also create a panel series with the
index labels s index and the rates here as the column.
So let's have a look here and here our max Sharpe Ratio portfolio we have 34 percent Amazon then 17
percent Boeing almost 0 percent Disney and IBM and also Microsoft and the 45 percent Coca-Cola.
And here we can see one pitfall of creating forward looking portfolios and optimizing them for the best
portfolio.
So this leads typically to concentrated positions and this portfolio is clearly not a perfectly diversified
portfolio.
That's one pitfall and in the next video we will discover some more problems and pitfalls.
So I hope to see you there by.